package dgut.haitaobao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dgut.haitaobao.entry.ProductParams;
import dgut.haitaobao.mapper.ProductParamsMapper;
import dgut.haitaobao.service.ProductParamsService;
import dgut.haitaobao.util.response.HttpResponse;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductParamsServiceImpl implements ProductParamsService {
    @Resource
    private ProductParamsMapper productParamsMapper;
    @Override
    public HttpResponse getProductParamsByProductId(String productId) {
        QueryWrapper<ProductParams> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("product_id", productId);
        List<ProductParams> productParams = productParamsMapper.selectList(queryWrapper);
        if (!CollectionUtils.isEmpty(productParams)) {
            return HttpResponse.success(productParams.get(0));
        }else {
            return HttpResponse.error("三无产品");
        }
    }

    @Override
    public HttpResponse getBrandsByCategoryId(String categoryId) {
        List<String> brands = productParamsMapper.getBrandByCategoryId(categoryId);
        return HttpResponse.success(brands);
    }

    @Override
    public HttpResponse getBrandsByProductName(String productName) {
        List<String> brands = productParamsMapper.getBrandByProductName("%"+productName+"%");
        return HttpResponse.success(brands);
    }
}
